#pragma once
#include <vector>

const double EPS = 1e-5;

class TGPoint {
public:
    double x,y;
    TGPoint(const double& x, const double& y):x(x),y(y){}
    TGPoint() {
        x = 0.0;
        y = 0.0;
    }
    TGPoint(const TGPoint& p1): x(p1.x), y(p1.y) {}
    void set(double _x, double _y);
    double pdis(TGPoint& p);
    TGPoint& operator = (const TGPoint&);
    bool operator < (const TGPoint&)const;
    double operator * (const TGPoint&)const; //计算向量点积
    double operator ^ (const TGPoint&)const; //计算向量叉积
    const TGPoint operator-()const;
    //bool operator == (const TGPoint&)const;
};

//计算两点之间距离
double pdist(const TGPoint& p1, const TGPoint& p2);

// bool operator==(const TGPoint& p1, const TGPoint& p2);
// bool operator==(TGPoint& p1, TGPoint& p2);
TGPoint operator-(const TGPoint& p1, const TGPoint& p2);
TGPoint operator+(const TGPoint& p1, const TGPoint& p2);
TGPoint operator/(const TGPoint& p, const double&);
double xmul(TGPoint&, TGPoint&);
double xmul(const TGPoint&, const TGPoint&);
//判断两个浮点数在给定精度下的大小关系 0:等于，1：大于，-1：小于
int dcmp(const double& src, const double& dst=0.0);
//判断两个坐标是否相等
bool equal(TGPoint&, TGPoint&);
bool equal(const TGPoint&, const TGPoint&);

/*
使用分治法求给定点集中的最近点对，将结果存入ret中
*/
double nearestPairWithDivideAndConquer(std::vector<TGPoint>& points, std::pair<TGPoint, TGPoint>& ret);

//暴力法求平面最近点对并将其放入ret
double nearestPairWithBruteForce(std::vector<TGPoint>& points, std::pair<TGPoint, TGPoint>& ret);

double nearestPairWithBruteForce(std::vector<TGPoint>& points);

//三点确定圆心,如果三点共线则返回false。如果不同线则返回true并将圆心存入dst中
bool findCircleCenterWith3Points(const TGPoint&, const TGPoint&, const TGPoint&, TGPoint& dst);

//找到点集中最小覆盖圆
void minimumCoveringCircle(std::vector<TGPoint>& points, TGPoint& center, double& radius);